package utils

import "time"

// UnixToData 时间戳转成日期
func UnixToData(timestamp int, formatLayout string) string {
	t := time.Unix(int64(timestamp), 0)
	return t.Format(formatLayout)
}

// DataToUnix 日期转成时间戳  如：("2022-02-03 15:04:05","2006-01-01 15:04:05")
func DataToUnix(date string, formatLayout string) (int64, error) {
	t, err := time.ParseInLocation(formatLayout, date, time.Local)
	if err != nil {
		return 0, err
	}
	return t.Unix(), nil
}

// GetUnix 获取当前时间戳
func GetUnix() int64 {
	return time.Now().Unix()
}

// GetDate 获取当前日期
func GetDate(formatLayout string) string {
	return time.Now().Format(formatLayout)
}
